package com.nus.application.web.base.listener;

import com.opensymphony.xwork2.util.LocalizedTextUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ActionGlobalMessagesListener implements ServletContextListener {

    private static Log log = LogFactory.getLog(ActionGlobalMessagesListener.class.getName());
    private static final String[] DEFAULT_RESOURCES = new String[]{
        "com.label"
    };

    /**
     * Uses the LocalizedTextUtil to load messages from the global message
     * bundle.
     *
     * @see
     * javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Servle
     * tContextEvent)
     */
    @Override
    public void contextInitialized(ServletContextEvent arg0) {

        for (String resourceName : DEFAULT_RESOURCES) {
            log.info("Loading " + resourceName);
            LocalizedTextUtil.addDefaultResourceBundle(resourceName);
        }
        log.info("Global messages loaded.");
    }

    /**
     * @see
     * javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
     */
    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        // do nothing
    }
}